package com.xb.sourest.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.ocnyang.cartlayout.CartAdapter;
import com.ocnyang.cartlayout.viewholder.CartViewHolder;
import com.xb.sourest.R;
import com.xb.sourest.bean.ShopGoodsBean;
import com.xd.navi.GlideUtils;
import com.xd.navi.PhoneUtils;

import java.util.List;

import androidx.annotation.NonNull;

public class ShopCarAdapter extends CartAdapter<CartViewHolder> {

    public ShopCarAdapter(Context context, List datas) {
        super(context, datas);
    }


    @Override
    protected CartViewHolder getNormalViewHolder(View itemView) {
        return  (CartViewHolder) (new NomalViewHolder(itemView, R.id.checkbox) {
            @Override
            public void onNeedCalculate() {
                if (onCheckChangeListener != null) {
                    onCheckChangeListener.onCalculateChanged(null);
                }
            }
        });
    }

    @Override
    protected CartViewHolder getGroupViewHolder(View itemView) {
        return (CartViewHolder) new GroupViewHolder(itemView, R.id.checkbox);
    }

    @Override
    protected CartViewHolder getChildViewHolder(View itemView) {
        return (CartViewHolder) (new ChildViewHolder(itemView, R.id.checkbox) {
            @Override
            public void onNeedCalculate() {
                if (onCheckChangeListener != null) {
                    onCheckChangeListener.onCalculateChanged(null);
                }
            }
        });
    }

    @Override
    protected int getChildItemLayout() {
        return R.layout.shop_item_child;
    }

    @Override
    protected int getGroupItemLayout() {
        return 0;
    }

    @Override
    protected int getNormalItemLayout() {
        return 0;
    }

    @Override
    public void onBindViewHolder(@NonNull CartViewHolder holder, final int position) {
        super.onBindViewHolder(holder, position);
        if (holder instanceof ChildViewHolder) {
            ChildViewHolder childViewHolder = (ChildViewHolder) holder;
            childViewHolder.textView.setText(((ShopGoodsBean) mDatas.get(position)).getGoods_name());
            childViewHolder.textViewPrice.setText("￥" +  PhoneUtils.fromatAmount(((ShopGoodsBean) mDatas.get(position)).getGoods_price()));
      //      childViewHolder.textViewNum.setText(String.valueOf(((ShopGoodsBean) mDatas.get(position)).getGoods_amount()));
            GlideUtils.load(((ShopGoodsBean) mDatas.get(position)).getImg(),childViewHolder.draw_goods,R.mipmap.icon_error);
            childViewHolder.addSubtractLayout.setCurrentNumber(((ShopGoodsBean) mDatas.get(position)).getGoods_amount());
            Log.e("位置----", "onBindViewHolder: " + holder.getLayoutPosition() + "----adpter--" + holder.getAdapterPosition());

        } else if (holder instanceof GroupViewHolder) {
            //GroupViewHolder groupViewHolder = (GroupViewHolder) holder;
           // groupViewHolder.textView.setText(((ShopTitleBean) mDatas.get(position)).getShop_name());
        } else if (holder instanceof NomalViewHolder) {
          //  NomalViewHolder normalViewHolder = (NomalViewHolder) holder;
          //  normalViewHolder.textView.setText(((ShopGoodsBean) mDatas.get(position)).getGoods_name());
          //  normalViewHolder.textViewPrice.setText("￥" + PhoneUtils.fromatAmount(((ShopGoodsBean) mDatas.get(position)).getGoods_price()));
          //  normalViewHolder.addSubtractLayout.setCurrentNumber(((ShopGoodsBean) mDatas.get(position)).getGoods_amount());
        }
    }
}
